Object.defineProperty(exports, "__esModule", {
  value: true
});
var $AutoPool = require("AutoPool");
var def_GlobalPool = function () {
  function _ctor() { }
  _ctor.createPool = function (t, e, o) {
    this.allPools.hasOwnProperty(t) || (this.allPools[t] = new $AutoPool.AutoNodePool(e, o));
  };
  _ctor.get = function (t, e) {
    if (this.allPools[t]) {
      return this.allPools[t].get(e);
    } else {
      console.warn("未创建对应名称的对象池，获取实例失败：", t);
      return null;
    }
  };
  _ctor.put = function (t, e) {
    e || (e = t.name);
    if (!this.allPools[e]) {
      console.warn("未创建对应名称的对象池，将销毁节点：", e);
      var o = t.getComponent(e);
      o && o.unuse && o.unuse();
      return void t.destroy();
    }
    this.allPools[e].put(t);
  };
  _ctor.putAllChildren = function (t) {
    for (var e = t.childrenCount - 1; e >= 0; --e) {
      var o = t.children[e];
      this.put(o);
    }
  };
  _ctor.destroyAllChildren = function (t) {
    for (var e = t.childrenCount - 1; e >= 0; --e) {
      t.children[e].destroy();
    }
  };
  _ctor.clear = function (t) {
    // 清理指定的池或清空所有池
    if (t) {
      // 如果有指定池的键
      if (this.allPools.hasOwnProperty(t)) {
        this.allPools[t].clear(); // 清理指定池
        delete this.allPools[t]; // 删除该池
      }
    } else {
      // 清空所有池
      for (const key in this.allPools) {
        this.allPools[key].clear(); // 清理每个池
      }
      this.allPools = {}; // 重置为新的空对象
    }
  };
  _ctor.getSize = function (t) {
    if (this.allPools[t]) {
      return this.allPools[t].count;
    } else {
      return 0;
    }
  };
  _ctor.preCreate = function (t, e) {
    if (this.allPools[t]) {
      this.allPools[t].preCreate(e);
    } else {
      console.warn("不存在对应名称的对象池，无法预先创建实例：", t);
    }
  };
  _ctor.allPools = {};
  return _ctor;
}();
exports.default = def_GlobalPool;